﻿using System.Linq;
using JetBrains.Annotations;

namespace StreetPacMan.Server
{
    public interface IEventsStorage
    {
        GameEvent[] GetAllGameEvents(int gameId);
    }

    [UsedByIoc]
    public class EventsStorage : IEventsStorage
    {
        private readonly IConnectionProvider _ConnectionProvider;

        public EventsStorage(IConnectionProvider connectionProvider)
        {
            _ConnectionProvider = connectionProvider;
        }

        public GameEvent[] GetAllGameEvents(int gameId)
        {
            using (var dbConnection = _ConnectionProvider.GetConnection())
            using (var pacManDataContext = new PacManDataContext(dbConnection))
            {
                return pacManDataContext.GameEvents.Where(x => x.GameId == gameId).ToArray();
            }
        }
    }
}